<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}">
    <link rel="icon" type="image/ico" sizes="144x144" href="../static/images/favicon.ico"
          th:href="@{/images/favicon.ico}"/>
    <!--排版-->
    <link rel="stylesheet" href="../static/css/typo.css">
    <!--动画-->
    <link rel="stylesheet" href="../static/css/animate.css">
    <!--代码高亮-->
    <link rel="stylesheet" href="../static/lib/prism/prism.css">
    <!--目录生成-->
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>

</head>

<body>
<!--导航-->
<nav th:replace="_fragments :: menu(0)" class="ui inverted attached segment m-padded-tb-mini">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header secondary item">Blog</h2>
            <a href="#" class="m-item item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="clone icon"></i>归档</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="info icon"></i>关于我</a>
            <div class="right item m-mobile-hide">
                <div class="ui category search">
                    <div class="ui icon input">
                        <input class="prompt" type="text" placeholder="Search animals...">
                        <i class="search icon"></i>
                    </div>
                    <div class="results"></div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!--中间内容 m-container样式 左右存在间距-->
<div id="waypoint" class="m-container m-padded-tb-big animated fadeIn">
    <!--根据屏幕的尺寸达到最好的效果 attached浮加  bottom,top圆角-适应移动端-->
    <div class="ui container">
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <!--头像avatar-->
                <div class="item">
                    <img class="ui avatar image" th:src="@{${blog.user.avatar}}" src="https://picsum.photos/100/100"
                         alt="">
                    <div class="content">
                        <a href="#" th:text="${blog.user.nickname}" class="ui pink label m-padded-mini">
                            Andy
                        </a>
                    </div>
                </div>
                <!--日期-->
                <div class="item">
                    <i class="calendar icon"></i> <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2021-3-17</span>
                </div>
                <!--浏览次数-->
                <div class="item">
                    <i class="eye icon"></i> <span th:text="${blog.views}">1212</span>
                </div>
            </div>
        </div>
        <!--图片区域-->
        <div class="ui attached segment">
            <img src="https://unsplash.it/800/450?image=1005" th:src="@{${blog.firstPicture}}" alt=""
                 class="ui fluid rounded image">
        </div>
        <div class="ui attached padded segment">
            <!--内容-->
            <div class="ui right aligned segment">
                <div class="ui orange label" data-value="原创" th:text="${blog.flag}">原创</div>
            </div>
            <h3 class="center aligned ui header" th:text="${blog.title}">听说，那片樱花又开了。</h3>
            <br/>
            <div id="content" th:utext="${blog.content}"
                 class="typo js-toc-content typo-selection m-padded-lr-responsive m-padded-tb-large">
                <h5 id="appendix2">2、开源许可</h5>
                <h2>中间内容</h2>
            </div>
            <!--标签-->
            <div class="m-padded-lr">
                <div class="ui green left label" th:each="tag : ${blog.tags}" th:text="${tag.name}">论语</div>
            </div>
            <!--赞赏-->
            <div th:if="${blog.appreciation}">
                <div class="ui center aligned basic segment">
                    <button id="praiseButton" class="ui red circular button">赞赏</button>
                </div>
                <!--点击赞赏弹出二维码-->
                <div class="ui praiseQR flowing popup transition hidden">
                    <div class="ui red basic label">
                        <!--字体大小 inherit 继承上级-->
                        <div class="ui images" style="font-size: inherit">
                            <div class="image">
                                <img src="../static/images/wechatPay.jpg" th:src="@{/images/wechatPay.jpg}" alt=""
                                     class="ui rounded bordered image" style="width: 120px">
                                <div style="color: #2DAC67">WeChat</div>
                            </div>
                            <div class="image">
                                <img src="../static/images/alipay.jpg" th:src="@{/images/alipay.jpg}" alt=""
                                     class="ui rounded bordered image" style="width: 120px">
                                <div style="color: #1A75FF">Alipay</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="whetherLike-container" class="ui center aligned basic segment">
                <div class="whetherLike" th:fragment="whetherLike">
                    <input type="hidden" name="praise" th:value="${blog.praise}">
                    <input type="hidden" name="yuck" th:value="${blog.yuck}">
                    <div class="ui buttons">
                        <div class="ui left labeled button" tabindex="0">
                            <div class="ui grey basic label">
                                <span id="praiseCount" th:fragment="praiseCount" th:text="${blog.praise}">2048</span>
                            </div>
                            <button id="like-btn" class="ui button">
                                <i class="heart icon"></i>Like
                            </button>
                        </div>
                        <div class="grey or" data-text="or"></div>
                        <div class="ui labeled button" tabindex="0">
                            <button id="dislike-btn" class="ui button">
                                <i class="heartbeat icon"></i>Yuck
                            </button>
                            <a class="ui basic grey label">
                                <span id="yuckCount" th:fragment="yuckCount" th:text="${blog.yuck}">2048</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div class="ui attached positive message" th:if="${blog.shareStatement}">
            <!--博客信息-->
            <div class="ui middle vertical grid">
                <div class="eleven wide column">
                    <ui class="list">
                        <li>作者：<span style="font-weight: bold" th:text="${blog.user.nickname}">ANDY</span><a href="#"
                                                                                                             th:href="@{/about}"
                                                                                                             target="_blank">（联系作者）</a>
                        </li>
                        <li>发表时间：<span style="font-weight: bold"
                                       th:text="${#dates.format(blog.createTime,'yyyy-MM-dd HH:mm')}">2021-3-17 09:20</span>
                        </li>
                        <li>版权声明:<b>自由转载-非商用-非衍生-保持署名&nbsp;(创意共享3.0许可证)</b></li>
                        <li>联系作者: <b>请在文末添加作者二维码</b></li>
                    </ui>
                </div>
                <div class="five wide column">
                    <img src="images/wechat.jpg" alt="" class="ui right floated rounded bordered images"
                         style="width: 110px">
                </div>
            </div>
        </div>

        <div class="ui bottom attached segment" th:if="${blog.commentSwitch}">
            <!--留言区域列表-->
            <div id="comment-container" class="ui teal segment">
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%">
                        <h3 class="ui dividing header">Comments</h3>
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img src="../static/images/comment.png" th:src="@{${comment.avatar}}" alt="">
                            </a>
                            <div class="content">
                                <a class="author" th:text="${comment.nickname}">Matt</a>
                                <div class="ui mini basic red left pointing label m-padded-mini"
                                     th:if="${comment.adminComment}">博猪
                                </div>
                                <div class="metadata">
                                    <span class="date"
                                          th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                </div>
                                <div class="text" th:text="${comment.content}">
                                    How artistic!
                                </div>
                                <div class="actions">
                                    <a class="reply"
                                       th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}"
                                       data-commentid="1" data-commentnickname="Matt" onclick="reply(this)">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
                                <div class="comment" th:each="reply : ${comment.replyComments}">
                                    <a class="avatar">
                                        <img src="../static/images/comment.png" th:src="@{${reply.avatar}}" alt="">
                                    </a>
                                    <div class="content">
                                        <a class="author">
                                            <span th:text="${reply.nickname}">小红</span>
                                            <div class="ui mini basic red left pointing label m-padded-mini"
                                                 th:if="${reply.adminComment}">博猪
                                            </div>
                                            &nbsp;<span th:text="|@ ${reply.parentCommentName}|"
                                                        class="m-teal">@ 小白</span>
                                        </a>
                                        <div class="metadata">
                                            <span class="date"
                                                  th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">
                                            How artistic!
                                        </div>
                                        <div class="actions">
                                            <a class="reply"
                                               th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}"
                                               data-commentid="1" data-commentnickname="Matt"
                                               onclick="reply(this)">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>

                        </div>


                        <!--/*-->
                        <div class="comment">
                            <a class="avatar">
                                <img src="https://picsum.photos/100/100" alt="">
                            </a>
                            <div class="content">
                                <a class="author">Elliot Fu</a>
                                <div class="metadata">
                                    <span class="date">Yesterday at 12:30AM</span>
                                </div>
                                <div class="text">
                                    <p>This has been very useful for my research. Thanks as well!</p>
                                </div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                            <div class="comments">
                                <div class="comment">
                                    <a class="avatar">
                                        <img src="https://picsum.photos/100/100" alt="">
                                    </a>
                                    <div class="content">
                                        <a class="author">Jenny Hess</a>
                                        <div class="metadata">
                                            <span class="date">Just now</span>
                                        </div>
                                        <div class="text">
                                            Elliot you are always so right :)
                                        </div>
                                        <div class="actions">
                                            <a class="reply">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="comment">
                            <a class="avatar">
                                <img src="https://picsum.photos/100/100" alt="">
                            </a>
                            <div class="content">
                                <a class="author">Joe Henderson</a>
                                <div class="metadata">
                                    <span class="date">5 days ago</span>
                                </div>
                                <div class="text">
                                    Dude, this is awesome. Thanks so much
                                </div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                        </div>
                        <!--*/-->
                    </div>
                </div>

            </div>
            <!--提交留言-->
            <div id="comment-form" class="ui form">
                <input type="hidden" name="blogId" th:value="${blog.id}">
                <input type="hidden" name="parentCommentId" value="-1">
                <div class="field">
                    <textarea name="content" placeholder="大神，留下你的评论吧!"></textarea>
                </div>
                <div class="fields">
                    <!--评论姓名-->
                    <div class="field m-mobile-wide m-margin-bottom">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名"
                                   th:value="${session.user}!=null ? ${session.user.nickname}">
                        </div>
                    </div>
                    <!--评论邮箱-->
                    <div class="field m-mobile-wide m-margin-bottom">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱"
                                   th:value="${session.user}!=null ? ${session.user.email}">
                        </div>
                    </div>
                    <!--发表评论-->
                    <div class="field m-margin-bottom m-mobile-wide">
                        <button id="commentpost-btn" type="button" class="ui blue button m-mobile-wide">
                            <i class="icon edit"></i> 发表评论
                        </button>
                    </div>
                </div>
            </div>
        </div>


    </div>
</div>

<!--回到顶部-->

<div id="toolbar" class="m-fixed m-right-bottom" style="display: none">
    <div class="ui vertical buttons">
        <button type="button" id="toc-button" class="ui toc button">目录</button>
        <a href="#comment-container" class="ui button">留言</a>
        <button class="ui wechat icon button"><i class="large weixin icon"></i></button>
        <div id="toTop-button" class="ui icon button"><i class="big arrow circle up icon"></i></div>
    </div>
</div>


<div class="ui toc-container flowing popup transition hidden" style="width: 250px!important;">
    <ol class="js-toc">

    </ol>
</div>

<!--微信弹出QR-->
<div id="qrcode" class="ui wechat-qr flowing popup transition hidden">
</div>

<br>
<br>
<!--底部footer-->
<footer th:replace="_fragments :: footer" class="ui inverted divided vertical segment m-padded-tb-massive">
</footer>
<!--/*/<th:block th:replace="_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery-scrollTo/2.1.2/jquery.scrollTo.min.js"></script>
<script src="../static/lib/prism/prism.js" th:src="@{/lib/prism/prism.js}"></script>
<script src="../static/lib/tocbot/tocbot.min.js" th:src="@{/lib/tocbot/tocbot.min.js}"></script>
<script src="../static/lib/waypoints/jquery.waypoints.min.js"
        th:src="@{/lib/waypoints/jquery.waypoints.min.js}"></script>
<!--自动生成对应网页的QR码-->
<script src="../static/lib/qrcode/qrcode.min.js" th:src="@{/lib/qrcode/qrcode.js}"></script>
<!--/*/</th:block>/*/-->


<script th:inline="javascript">
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });
    <!--自动生成对应网页的QR码-->
    var serurl = /*[[#{blog.serurl}]]*/"127.0.0.1:8080";
    var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
        text: serurl + url,
        width: 110,
        height: 110,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });

    /*--滚动监听--*/
    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function (direction) {
            if (direction == 'down') {
                $('#toolbar').show(100);
            } else {
                $('#toolbar').hide(500);
            }
            console.log('Scrolled to waypoint!  ' + direction);
        }
    })

    $('#praiseButton').popup({
        popup: $('.praiseQR.popup'),
        on: 'click',
        position: 'top center'
    });
    /*-- 目录生成插件的初始化--*/
    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
    });

    $('#toc-button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    });
    $('.wechat').popup({
        popup: $('.wechat-qr'),
        on: 'hover',
        position: 'left center'
    });
    $('#toTop-button').click(function () {
        $(window).scrollTo(0, 500);
    });

    //评论表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }
                ]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的大名'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });
    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log('校验成功');
            postData();
        } else {
            console.log('校验失败');
        }

    });
    /*评论点赞*/
    $('#like-btn').click(function () {
        $('#praiseCount').load(/*[[@{/blog/{blogId}/praise(blogId = ${blog.id})}]]*/);
        this.setAttribute("class", "ui red button");
    });
    /*评论点踩*/
    $('#dislike-btn').click(function () {
        $('#yuckCount').load(/*[[@{/blog/{blogId}/yuck(blogId = ${blog.id})}]]*/);
        this.setAttribute("class", "ui black button");
    });


    $(function () {
        $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"comments/49");
    });

    function postData() {
        $("#comment-container").load(/*[[@{/comments}]]*/"", {
            "parentCommentId": $("[name='parentCommentId']").val(),
            "blogId": $("[name='blogId']").val(),
            "nickname": $("[name='nickname']").val(),
            "email": $("[name='email']").val(),
            "content": $("[name='content']").val()
        }, function (responseTxt, statusTxt, xhr) {
//        $(window).scrollTo($('#comment-container'),500);
            clearContent();
        });
    }

    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentCommentId']").val(-1);
        $("[name='content']").attr("placeholder", "大神，留下你的评论吧!");
    }


    // 驼峰命名可能取不到值,data-commentid 用data('commentid') 会自动加上data
    function reply(obj) {
        let commentId = $(obj).data('commentid');
        let commentNickname = $(obj).data('commentnickname');
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        $("[name='parentCommentId']").val(commentId);
        $(window).scrollTo($('#comment-form'), 500);
    }

</script>

</body>
</html>
